import { ref } from 'vue'
import useRequet, { RespData } from "./network"
import { DataStruc } from "./datastruc";
import { ElMessage } from 'element-plus';

export default function getConfgin(id: number) {
  const request = useRequet({ path: "" })
  let groupData = ref<DataStruc[]>([])
  let groupDataList = ref([] as DataStruc[])
  let groupDataAdd = ref([] as DataStruc[])
  let groupDataUpdate = ref([] as DataStruc[])
  let groupDataDetails = ref([] as DataStruc[])
  
  request.sendRequest({
    address: 'system/config/getConfig',
    params: {
      groupId: id
    },
    success: (resp: RespData) => {
      if(resp.code != 0) return ElMessage('获取配置' + resp.msg)
      groupData.value = resp.data
      resp.data.forEach((item: DataStruc) => {
        if(item.listView === 1) {
          groupDataList.value.push(item)
        }
        if(item.insertShow === 1) {
          groupDataAdd.value.push(item)
        }
        if(item.canUpdate === 1) {
          groupDataUpdate.value.push(item)
        }
        if(item.canShow === 1) {
          groupDataDetails.value.push(item)
        }
      })
      console.debug("结构成功");
    },
    fail: (resp: RespData) => {
      console.debug("结构失败", resp);
    },
    method: "POST",
  })

  return {groupData , groupDataList, groupDataAdd, groupDataUpdate, groupDataDetails} 
}





